<template>
  <div id="app">
    <router-view/>
  </div>
</template>

<script>
import jwt_decode from "jwt-decode"
export default {
  name: 'App',
  mounted(){
    const token= localStorage.getItem("eletoken");
    if(token){
      //解析token 
      const decode = jwt_decode(token);
      //报错到vuex中
      this.$store.dispatch("setAuthenticated",!this.isEmpty(decode));
      this.$store.dispatch("setUser",decode);
    }
  },
  methods:{
    isEmpty(value){
        return (
          value === undefined || 
          value === null ||
          ( typeof value ==="object" && Object.keys(value).length===0)||
          ( typeof value ==="string" && value.trim().length===0)
        );
      }
  }
}
</script>

<style>
html,body{
  height: 100%;
}
#app{
  height: 100%;
  width: 100%;
}
</style>
